﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CodeFinder.Web.Models;
using CodeFinder.Common.Interfaces;

namespace CodeFinder.Web.Controllers
{
    public class HomeController : BaseController {
        private const int PAGE_SIZE = 10;
        private IPostService m_postService;
        public HomeController(IPostService service) {
            m_postService = service;
        }
        public ActionResult Index(int page = 1) {
            var posts = m_postService.Posts
                .OrderBy(x => x.Id)
                .Skip((page - 1) * PAGE_SIZE)
                .Take(PAGE_SIZE).ToList();
            BlogModel model = new BlogModel {
                Posts = posts,
                PageInfo = new PageInfo {
                    Totals = m_postService.CountPost(),
                    PageSize = PAGE_SIZE,
                    Current = page
                }
            };
            return View(model);
        }
    }
}
